package com._51cto.healthy.service;

import com._51cto.healthy.base.BaseMapper;
import com._51cto.healthy.content.P;
import com._51cto.healthy.mapper.DiseaseMapper;
import com._51cto.healthy.pojo.Disease;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class DiseaseServiceImpl implements DiseaseService{
    @Autowired
    private DiseaseMapper diseaseMapper;


    @Override
    public BaseMapper<Disease> getDao() {
        return diseaseMapper;
    }


    @Override
    public P<Disease> findDisease(String query, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        List<Disease> all = diseaseMapper.findAll(query);
        PageInfo<Disease> pageInfo = new PageInfo<>(all);

        return new P<Disease>().setPageNum(pageInfo.getPageNum())
                .setPageSize(pageInfo.getPageSize())
                .setRows(pageInfo.getList())
                .setTotal(pageInfo.getTotal())
                .setPages(pageInfo.getPages());
    }

    @Override
    public void deleteByPK(Integer pk) {
        DiseaseService.super.deleteByPK(pk);
    }

    @Override
    public void insert(Disease entity) {
        DiseaseService.super.insert(entity);
    }

    @Override
    public void update(Disease entity) {
        DiseaseService.super.update(entity);
    }
}
